package com.demo.gulimall.cart.config;

import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author Chen Yuan
 * @create 2023-06-16  10:23
 */
@Configuration
public class MySessionConfig {

	@Bean
	public CookieSerializer cookieSerializer(){
		DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

		// 修改作用域, 指定作用域为父域
		cookieSerializer.setDomainName("mall.com");
		// 修改 Cookie 名称
		cookieSerializer.setCookieName("MALLSESSION");

		return cookieSerializer;
	}

	// 重新实现 Redis 序列化机制, 使用 fastJson
	@Bean
	public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
		return new GenericFastJsonRedisSerializer();
	}
}
